package com.example.demo.test;


import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.util.Strings;
import org.apache.pdfbox.multipdf.Splitter;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.text.PDFTextStripper;
import org.junit.Test;
import org.springframework.boot.test.context.SpringBootTest;

import java.io.File;
import java.io.IOException;
import java.util.List;

@SpringBootTest
public class pdf {

    @Test
    public void createPdf(){
        PDDocument pdDocument = new PDDocument();
        PDPage pdPage = new PDPage();
        pdDocument.addPage(pdPage);
        try {
            pdDocument.save("D:/ad.pdf");
            pdDocument.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @Test
    public void loadPdf(){
        PDDocument pdDocument;

        try {
            pdDocument = PDDocument.load(new File("D:/shopee 面单pdf 多张.pdf"));

            PDFTextStripper pdfTextStripper = new PDFTextStripper();

            Splitter splitter = new Splitter();
            List<PDDocument> pageLists = splitter.split(pdDocument);

            for (PDDocument pageList : pageLists) {
                String text = pdfTextStripper.getText(pageList);
                System.out.println("text = " + text);
            }

            pdDocument.save("D:/newPdf.pdf");

            pdDocument.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @Test
    public void xxx(){
        String a = null;
        System.out.println("Strings的为空判断");
        System.out.println(Strings.isBlank(""));
        System.out.println(Strings.isBlank(" "));
        System.out.println(Strings.isBlank(a));

        System.out.println("StringUtils的为空判断");

        System.out.println(StringUtils.isBlank(""));
        System.out.println(StringUtils.isBlank(" "));
        System.out.println(StringUtils.isBlank(a));


    }
}
